<?php
//
// Post or Get ?
//
function isPost() {
  if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
    return true;
}

function isGet() {
  if ( $_SERVER['REQUEST_METHOD'] == 'GET' )
    return true;
}

// 
// Requires a php file and puts its output inside
// a variable.
// 
function evaluateFile( $filename ) {
  if (is_file($filename)) {
    ob_start();
    include $filename;
    $contents = ob_get_contents();
    ob_end_clean();
    return $contents;
  }
  return false;
}

//    
// Renders a view inside a layout
// 
function render( $viewName, $layoutName="default.php" ) {
  $contentForLayout = evaluateFile($GLOBALS['VIEWS_PATH'] . $viewName);
  require_once $GLOBALS['LAYOUTS_PATH'] . $layoutName;
}

//
// Session functions
//
function s( $varname, $value ) {
  $_SESSION[ $varname ] = $value;
}

function g( $varname ) {
  if ( array_key_exists( $varname, $_SESSION ) ) {
    return $_SESSION[ $varname ];
  } else {
    return false;
  }
}

?>
